package com.sinothk.gpserver.modules.comm.serialNumber.controller;

import com.sinothk.gpserver.modules.comm.serialNumber.entity.SerialNumVo;
import com.sinothk.gpserver.modules.comm.serialNumber.service.SerialNumberService;
import com.sinothk.server.support.annotation.callback.BizException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

//@Api(tags = "序列号相关")
@RestController
@RequestMapping("/comm")
@Slf4j
public class SerialNumberController {

    private final SerialNumberService serialNumberService;

    public SerialNumberController(SerialNumberService serialNumberService) {
        this.serialNumberService = serialNumberService;
    }

//    @ApiOperation(value = "生成业务编号", notes = "生成业务编号")
    @GetMapping(value = "/getSerialNumber")
    public SerialNumVo getSerialNumber(@ApiParam("type: 用户/房间/群组") @RequestParam("type") String type) {
        if (StringUtils.isEmpty(type)) throw new BizException("类型Type不能为空");

        SerialNumVo serialNumVo = new SerialNumVo();
        serialNumVo.setId(UUID.randomUUID().toString());
        if ("用户".equals(type) || "房间".equals(type) || "群组".equals(type)) {
            serialNumVo.setCode(serialNumberService.generateSerialNumberByModelCode(type));
        } else {
            serialNumVo.setCode("type未定义");
        }
        return serialNumVo;
    }

}
